package com.ruitu.mall_98_2.order;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.widget.ImageView;

import com.beanu.arad.base.my_base.MyBaseActivity;
import com.beanu.arad.widget.NoScrollViewPager;
import com.beanu.arad.widget.progressactivity.ProgressLayout;
import com.ruitu.mall_98_2.R;
import com.ruitu.mall_98_2.order.fragment.CancleOrderFragment;
import com.ruitu.mall_98_2.order.fragment.OrderFragment;
import com.ruitu.mall_98_2.order.fragment.WaitingCommentFragment;
import com.ruitu.mall_98_2.order.fragment.WaitingPayFragment;
import com.ruitu.mall_98_2.order.fragment.WaitingReciverFragment;
import com.ruitu.mall_98_2.order.fragment.WaitingSendFragment;

public class MyOrderActivity extends MyBaseActivity {
    private TabLayout tabLayout;
    private NoScrollViewPager viewPager;
    private ViewPagerAdapter adapter;
    private ImageView iv_back;
    private String titleText[] = {"全部", "待付款", "待发货", "待收货", "待评价"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_my_order;
    }

    @Override
    protected ProgressLayout findProgressLayout() {
        return null;
    }

    @Override
    protected void initViews() {
        super.initViews();
        setHeadTitle("我的订单");
        tabLayout = findViewById(R.id.tabLayout);
        viewPager = findViewById(R.id.viewPager);
        iv_back = findViewById(R.id.iv_back);

        viewPager.setScanScroll(false);
        adapter = new ViewPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        int position = getIntent().getIntExtra("position", 0);
        viewPager.setCurrentItem(position);

        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    class ViewPagerAdapter extends FragmentPagerAdapter {

        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            if (position == 1) {
                return WaitingPayFragment.newInstance(position);
            } else if (position == 2) {
                return WaitingSendFragment.newInstance();
            } else if (position == 3) {
                return WaitingReciverFragment.newInstance();
            } else if (position == 4) {
                return WaitingCommentFragment.newInstance();
            }
            return OrderFragment.newInstance();
        }

        @Override
        public int getCount() {
            return titleText.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titleText[position];
        }

    }
}
